<?php
class Default_Form_Search extends Zend_Form{
    
    public function init(){
        
        $this->setName("default");
        $this->setAction('/index');        
                
        $view = new Zend_Form_Element_Hidden('view');
        $view->addFilter('Int');        
        $view->removeDecorator('dtddwrapper')->removeDecorator('HtmlTag')->removeDecorator('Label');
        
        $value = new Zend_Form_Element_Text('title');
        $value->addFilter('StripTags')->addFilter('StringTrim');
        $value->setAttrib('class','form-control')->setAttrib('placeholder','Tìm kiếm')->setAttrib('style','width:30%');        
        $value->removeDecorator('dtddwrapper')->removeDecorator('HtmlTag')->removeDecorator('Label');
        
        $catalog= new Zend_Form_Element_Select('itemId');        
        $catalog->setAttrib('class','form-control')->setAttrib('style','width:30%');
        $catalog->removeDecorator('dtddwrapper')->removeDecorator('HtmlTag')->removeDecorator('Label');
        $catalog->addMultiOption('-1','--- Tất cả danh mục ---');        
        $modeC = new Default_Model_Productcat();
        $modelI = new Default_Model_Productitem();        
        $catL = $modeC->getAllData();        
        foreach($catL as $o){
            $catalog->addMultiOption('cat_'.$o->id,'--- '.$o->name.' ---');
            $arrT[] = 'cat_'.$o->id;                         
            $itemL = $modelI->getDataByCat($o->id);            
            foreach($itemL as $t){
                $catalog->addMultiOption($t->id,$t->name);                  
            }      
        }               
        //$catalog->setAttrib('disable',$arrT);
                
        $area= new Zend_Form_Element_Select('areaId');        
        $area->setAttrib('class','form-control')->setAttrib('style','width:25%');
        $area->removeDecorator('dtddwrapper')->removeDecorator('HtmlTag')->removeDecorator('Label');
        $area->addMultiOption('-1','--- Tất cả khu vực ---');
        $modelA = new Default_Model_Area();
        $areaL = $modelA->getAllData()->toArray();
        foreach($areaL as $o){
            $area->addMultiOption($o['id'],$o['name']);
        }                           
           
        $transac = new Zend_Form_Element_Radio('transaction');
        $transac->setAttrib('class','radio-inline');        
        $configTran = new Zend_Config_Ini(CONFIG_PATH.'/transaction.ini', APPLICATION_ENV);
        $tranL=$configTran->transaction->toArray();
        foreach($tranL as $k => $v){            
            $transac->addMultiOption($k,$v);            
        }  
        $transac->setSeparator(' ');
        $transac->removeDecorator('dtddwrapper')->removeDecorator('HtmlTag')->removeDecorator('Label');
                                                                                                                                        
        $sm=new Zend_Form_Element_Button('submit');
        $sm->setAttrib('type','submit')->setAttrib('class','btn');
        $sm->setLabel('Tìm')->setAttrib('style','width:10%')
            ->removeDecorator('dtddwrapper');                                                                                 
        
        $this->setDecorators(array(
                               array('viewScript',
                               array('viewScript'=>'template/form_search.phtml'),
                        )));
                        
        $this->addElements(array(
            $value, $catalog, $area, $transac, $view, $sm
        ));                                                  
    }
}